var FKID;
require(['jquery', 'cookie', 'lay', 'vue', 'tool', 'framework', 'jquery-ui'], function ($) {
    $(".layui-container").css("width", "100%");
    $(".layui-container").css("padding", "0");
    layui.use(['form', 'tree'], function () {
        var form = layui.form;
        var tree = layui.tree;
        var layer = layui.layer;
        form.render();
        tree.render({
            elem: '.WidgetBox' //默认是点击节点可进行收缩
            , data: WidgetBox_VIEW
            , click: function (obj) {
                var data = obj.data;  //获取当前点击的节点数据
                cachePlan(data.id);
            }
        });
        form.on('select(WidgetTypes)', function (data) {
            switch (data.value) {
                case "view": {
                    tree.render({
                        elem: '.WidgetBox' //默认是点击节点可进行收缩
                        , data: WidgetBox_VIEW
                    });
                }
                    ;
                    break;
                case "model": {
                    tree.render({
                        elem: '.WidgetBox' //默认是点击节点可进行收缩
                        , data: WidgetBox_MODEL
                    });
                }
                    ;
                    break;
                case "control": {
                    tree.render({
                        elem: '.WidgetBox' //默认是点击节点可进行收缩
                        , data: WidgetBox_Control
                    });
                }
                    ;
                    break;
            }
        });
    });
    require(['vue'], function (Vue) {
        var laber = new Vue({
            el: ".laber",
            data: {
                object: "",
                type: ""
            }
        })
    });
    require(['jsPlumb','lumbTool'],function (jsPlumb) {
      /*  var json={};
        json['data']=[
            {
                "id":"lumb1",
                "name":"测试1",
                "top":"4em",
                "left":"2em",
                "type":"101"
            },
            {
                "id":"lumb2",
                "name":"测试2",
                "top":"15em",
                "left":"10em",
                "type":"101"
            },
            {
                "id":"lumb3",
                "name":"测试3",
                "top":"6em",
                "left":"20em",
                "type":"101"
            }
        ];
        json['line']=[
            {
                'id':'1-2',
                'begin':'lumb1',
                'end':'lumb2'
            },
            {
                'id':'2-3',
                'begin':'lumb2',
                'end':'lumb3'
            },
            {
                'id':'1-3',
                'begin':'lumb1',
                'end':'lumb3'
            }
        ]*/
         var json='{"data":[{"id":"lumb1","name":"测试1","top":"4em","left":"2em","type":"101"},{"id":"lumb2","name":"测试2","top":"15em","left":"10em","type":"101"},{"id":"lumb3","name":"测试3","top":"6em","left":"20em","type":"101"},{"id":"lumb1571022848914","name":"开始","top":"444px","left":"36px","type":"104"}],"line":[{"id":"1-2","begin":"lumb1","end":"lumb2"},{"id":"2-3","begin":"lumb2","end":"lumb3"},{"id":"1-3","begin":"lumb1","end":"lumb3"},{"begin":"lumb1571022848914","end":"lumb2","id":"1571022893052"}]}';
         json=JSON.parse(json);
        lumbLoad(jsPlumb,json,$("#canvas"));
    });

    window.oncontextmenu=function(e){
        e.preventDefault();
        var menu=$("#menu");
        menu.css("left",e.clientX+'px');
        menu.css("top",e.clientY+'px');
        menu.css("width",'auto');
        menu.css("display","block");
        menu.css("height","auto");
        menu.css("z-index","999");
        menu.css("background","white");
        FKID=e.target.id;
    }
    window.onclick=function(e){
        document.querySelector('#menu').style.height=0;
    }
});


function allowDrop(ev) {
    ev.preventDefault();
}

function drag(ev) {
    ev.dataTransfer.setData("Text", ev.target.id);
}

function drop(ev) {
    ev.preventDefault();
    var data = ev.dataTransfer.getData("Text");
    ev.target.appendChild(document.getElementById(data));

}

function cachePlan(funtions) {
    eval(funtions + "()");
}

//
function v_101() {
    var id="lumb"+getDete("r");
    _addFK(id,"角色审批节点","0em","0em","101");
}
function v_104() {
    var id="lumb"+getDete("r");
    _addFK(id,"开始","0em","0em","104");
}
function v_105() {
    var id="lumb"+getDete("r");
    _addFK(id,"结束","0em","0em","105");
}
function v_102() {
    var id="lumb"+getDete("r");
    _addFK(id,"单人审批节点","0em","0em","102");
}
function v_103() {
    var id="lumb"+getDete("r");
    _addFK(id,"会签","0em","0em","103");
}
function deleteFK() {
    _removeFK(FKID);
}